<template>
  <el-dialog :title="dialogText[dialogStatusParkMag]" :visible.sync="dialogCreateVisibleDialog" center>
    <el-form ref="createFormEquipmentMag" :rules="rulesParkMags" :inline="true" :model="tempParkMagDialog"
             :label-position="'left'"
             label-width="90px" style="text-align: left">
      <el-form-item label="设备ID" prop="equipment_no">
        <el-input clearable placeholder="请输入停车场编号" v-model="tempParkMagDialog.equipment_no"/>
      </el-form-item>
      <el-form-item label="设备位置" prop="equipment_site" style="margin-left: 50px">
        <el-input v-model="tempParkMagDialog.equipment_site" clearable placeholder="请输入停车场名称"></el-input>
      </el-form-item>
      <el-form-item label="设备类型" prop="equipment_type">
        <el-select v-model="tempParkMagDialog.equipment_type">
          <el-option v-for="item in equipmentTypes" :key="item.id" :label="item.value" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备型号" prop="park_sffs"  style="margin-left: 35px">
        <el-select v-model="tempParkMagDialog.equipment_model">
          <el-option v-for="item in equipmentModels" :key="item.id" :label="item.value" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="管理单位" prop="equipment_manager">
        <el-input v-model="tempParkMagDialog.equipment_manager" clearable placeholder="请选择管理单位" readonly></el-input>
      </el-form-item>
      <el-form-item label="维修单位" prop="equipment_operator"  style="margin-left: 50px">
        <el-input v-model="tempParkMagDialog.equipment_operator" clearable placeholder="请选择维修单位" readonly></el-input>
      </el-form-item>
      <el-form-item label="经度" prop="equipment_long">
        <el-input clearable placeholder="请输入经度" v-model="tempParkMagDialog.equipment_long"/>
      </el-form-item>
      <el-form-item label="纬度" prop="equipment_lati" style="margin-left: 50px">
        <el-input clearable placeholder="请输入纬度" v-model="tempParkMagDialog.equipment_lati"/>
      </el-form-item>
      <el-form-item label="采购时间" prop="park_sdate">
        <el-date-picker
          v-model="tempParkMagDialog.equipment_buy_time"
          type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="设备状态" prop="equipment_status">
        <el-select v-model="tempParkMagDialog.equipment_status">
          <el-option v-for="item in statusTypes" :key="item.id" :label="item.value" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="equipment_desc" >
        <el-input clearable placeholder="请输入备注" v-model="tempParkMagDialog.equipment_desc"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogCreateVisibleDialog = false" class="btn-search">取消</el-button>
      <el-button v-if="dialogStatusParkMag=='create'" type="primary" class="btn-search" @click="createDataParkMag">确定
      </el-button>
      <el-button v-else type="primary" @click="updateDataEquipmentMag" class="btn-search">确定</el-button>
    </div>
    <person-child-dialog-road :dialogRoadVisible.sync="dialogRoadVisiblParkMag"
                              @roadName="selectRoadNameParkMag"></person-child-dialog-road>
    <person-child-dialog-dw :dialogDwVisible.sync="dialogDwVisibleParkMg" @dwName="selectDwnameParkMag"
                            :dwType="dwTypeParkMag"></person-child-dialog-dw>
  </el-dialog>
</template>

<script>
  /* eslint-disable */
  import PersonChildDialogDw from "../../organizationManagement/personChild/personChildDialogDw";
  import PersonChildDialogRoad from "../../organizationManagement/personChild/personChildDialogRoad";
  import {selDictonary} from "../../../api/dictionary";
  import {getChargeStandard} from "../../../api/parkingResource/parkingMag";

  export default {
    created() {
      this.initData()
    },
    components: {
      PersonChildDialogRoad,
      PersonChildDialogDw
    },
    name: "creat-equipment-mag-dialog",
    props: ['dialogStatusParkMag', 'dialogVisible', 'tempParkMag'],
    watch: {
      dialogCreateVisibleDialog() {
        this.$emit('update:dialogVisible', this.dialogCreateVisibleDialog)
      },
      dialogVisible(val) {
        this.dialogCreateVisibleDialog = val
      },
      tempParkMag(val) {
        this.tempParkMagDialog = val
      }
    },

    data() {
      return {
        dialogText: {create: '新增', update: '编辑'},
        dialogCreateVisibleDialog: false,
        dialogDwVisibleParkMg: false,
        dialogRoadVisiblParkMag: false,
        tempParkMagDialog: {
          park_no: '',
          park_name: '',
          park_placeno: '',
          park_placeStart: '001',
          park_ssdw: '',
          park_ssdwname: '', park_sfbzname: '',
          park_sfbz: '', park_roadno: '', park_road: '', park_dllx: '',
          park_jdbsc: '', park_sroad: '', park_eroad: '', park_dlnc: '',
          park_sffs: '', park_jcfs: '', park_long: '', park_lati: '',
          park_sdate: '', park_edate: '', park_status: '1', park_remark: '',
          equipment_no: '',
          equipment_site: '',
          equipment_desc: '',
          equipment_status: '',
          equipment_type: '',
          equipment_person: '',
          equipment_model: '',
          equipment_manager: '',
          equipment_operator: '',
          equipment_buy_time: '',
          equipment_long: '',
          equipment_lati: '',
        },
        sfbzs: [],
        statuss: [],
        dllxs: [],
        dlncs: [],
        sffss: [],
        jcfss: [],
        equipmentTypes: [
          {id: '0', value: '诱导屏'},
          {id: '1', value: '其他'},
        ],
        equipmentModels: [
          {id: '0', value: '未知'},
          {id: '1', value: 'P16双色显示屏'},
          {id: '2', value: 'P32双色显示屏'},
        ],
        statusTypes: [
          {id: '0', value: '空闲'},
          {id: '1', value: '正常'},
          {id: '2', value: '故障'},
        ],
        dwTypeParkMag: 0,
        rulesParkMags: {
          park_no: [{required: true, message: '请输入停车场编号', trigger: 'blur'}],
          park_name: [{required: true, message: '请输入停车场名称', trigger: 'blur'}],
          park_placeno: [{required: true, message: '请输入泊位数', trigger: 'blur'}],
          park_ssdwname: [{required: true, message: '请选择单位编号', trigger: 'change'}],
          park_road: [{required: true, message: '请选择所在道路', trigger: 'change'}]
        }
      }
    },
    methods: {
      createDataParkMag() {
        this.$refs['createFormEquipmentMag'].validate((valid) => {
          if (valid) {
            this.$emit('createDataParkMag', this.tempParkMagDialog)
          }
        })
      },
      updateDataEquipmentMag() {
        this.$refs['createFormEquipmentMag'].validate((valid) => {
          if (valid) {
            this.$emit('updateDataEquipmentMag', this.tempParkMagDialog)
          }
        })
      },
      handleSelectDw() {
        this.dialogDwVisibleParkMg = true
      },
      selectDwnameParkMag(val) {
        this.tempParkMagDialog.park_ssdwname = val.orgname
        this.tempParkMagDialog.park_ssdw = val.orgno
        this.dialogDwVisibleParkMg = false
      },
      handleSelectRoad() {
        this.dialogRoadVisiblParkMag = true
      },
      selectRoadNameParkMag(val) {
        this.tempParkMagDialog.park_road = val.unitname
        this.tempParkMagDialog.park_roadno = val.unitno
        this.dialogRoadVisiblParkMag = false
      },
      initData() {
        selDictonary().then(res => {
          for (var item in res) {
            if (res[item].id == "ori") {//
              this.dlncs = res[item].comboboxDetailList
            } else if (res[item].id == "enableflag") {
              this.statuss = res[item].comboboxDetailList
            } else if (res[item].id == "roadtype") {
              this.dllxs = res[item].comboboxDetailList
            } else if (res[item].id == "sffs") {
              this.sffss = res[item].comboboxDetailList
            } else if (res[item].id == "jcfs") {
              this.jcfss = res[item].comboboxDetailList
            }
          }
        })
        getChargeStandard().then(res => {
          this.sfbzs = res
        })
      }
    }
  }
</script>

<style scoped>

</style>
